package com.example.environment.controller;

import com.example.environment.pojo.Feedback;
import com.example.environment.service.FeedbackService;
import com.example.environment.tools.common.ResultMsg;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;
    @GetMapping("/getAllFeedbackBySupervisor")
    public ResultMsg getAllFeedbackBySupervisor(HttpServletRequest httpServletRequest) {
        if(httpServletRequest.getAttribute("id")==null){
            return ResultMsg.failOp("没有登录信息");
        }
        return feedbackService.getAllFeedbackBySupervisor(httpServletRequest.getAttribute("id").toString());
    }

    @GetMapping("/addFeedback")
    public ResultMsg addFeedback(Feedback feedback, HttpServletRequest httpServletRequest) {
        if(httpServletRequest.getAttribute("id")==null){
            return ResultMsg.failOp("没有登录信息");
        }
        return feedbackService.saveById(feedback,httpServletRequest.getAttribute("id").toString());
    }

    @GetMapping("/getAllFeedback")
    public ResultMsg getAllFeedback(HttpServletRequest httpServletRequest) {
//        if(httpServletRequest.getAttribute("id")==null){
//            return ResultMsg.failOp("没有登录信息");
//        }
        return ResultMsg.successOp(feedbackService.getAllFeedback());
    }

    @GetMapping("/updateFeedbackById")
    public ResultMsg updateFeedbackById(Feedback feedback, HttpServletRequest httpServletRequest) {
        if(httpServletRequest.getAttribute("id")==null){
            return ResultMsg.failOp("没有登录信息");
        }
        return feedbackService.updateFeedbackById(feedback);
    }

    @GetMapping("/updateFeedbackById/{state}")
    public ResultMsg getAllFeedbackByState(@PathVariable("state") Integer state, HttpServletRequest httpServletRequest) {
//        if(httpServletRequest.getAttribute("id")==null){
//            return ResultMsg.failOp("没有登录信息");
//        }
        List<Map<String,Object>> feedbackList=feedbackService.getAllFeedbackByState(state);
        if(feedbackList==null){
            return ResultMsg.failOp("没有对应反馈列表");
        }
        return ResultMsg.successOp(feedbackList);
    }

}
